<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
</body>
<script>
  var arr = {
    name: 'HTML',
    scores: [
      {
        name: '张三',
        score: 90
      },
      {
        name: '李四',
        score: 91
      },
      {
        name: '王五',
        score: 80
      },
      {
        name: '马六',
        score: 99
      },
    ]
  }
  //Object.defineProperties()
  Object.defineProperties(arr, {
    total: {
      get(){
        //累加学员的成绩
        var t=0
        //遍历数组
        for(var i=0;i<this.scores.length;i++){
          t+=this.scores[i].score
        }
        return t
      }
    },
    avg: {
      get(){
        return this.total / this.scores.length
      }
    }
  })
  console.log(arr.total)
  console.log(arr.avg)
</script>
</html>